package com.woniuxy.ssm.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

/**
 * @program: JavaEE-EFD
 * @description: mvc配置类
 * @author: fengjd
 * @create: 2022-07-29 09:00
 **/
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.woniuxy.ssm.controller")
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    ViewResolver viewResolver(){
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/views");
        viewResolver.setSuffix(".jsp");
        viewResolver.setViewClass(JstlView.class);
        return viewResolver;
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry resolverRegistry){
        resolverRegistry.viewResolver(viewResolver());
    }

    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/").setViewName("login");
    }

}
